package com.he;

import com.google.gson.GsonBuilder;
import com.he.websocket.WebsocketHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.socket.TextMessage;

/**
 * 工具类
 */
class LoggerUtil {

    private static Logger logger;

    public static void info(String message, Class tclass) {
        logger = LoggerFactory.getLogger(tclass);
        logger.info(message);
        sendWebSocket(message);

    }

    public static void error(String message, Class tclass) {
        logger = LoggerFactory.getLogger(tclass);
        sendWebSocket(message);
        logger.error(message);
    }

    private static void sendWebSocket(String message) {
        WebsocketHandler.broadcast(new TextMessage(new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create().toJson(message)));
    }
}
